package org.luo.iot.domain.land;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.luo.common.common.Result;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/land")
@Tag(name = "地块", description = "地块")
@RequiredArgsConstructor
@Slf4j
public class LandController {

    private final LandService landService;

    @PostMapping
    @Operation(summary = "添加地块", description = "添加地块")
    public Result<Land> save(Land land){
        landService.save(land);
        return Result.success(land);
    }

    @PutMapping
    @Operation(summary = "修改地块", description = "修改地块")
    public Result update(Land land){
        landService.updateById(land);
        return Result.success();
    }

    @DeleteMapping("{id}")
    @Operation(summary = "删除地块", description = "删除地块")
    public Result delete(@PathVariable Long id){
        landService.removeById(id);
        return Result.success();
    }

    @GetMapping("/page")
    @Operation(summary = "分页查询", description = "分页查询")
    public Result<Page<Land>> page(
            @RequestParam Integer pageNum,
            @RequestParam Integer pageSize
    ){

        Page<Land> page = landService.page(pageNum, pageSize);
        return  Result.success(page);
    }

}
